package com.xhh.interview.listener;

import com.xhh.common.constants.InterviewConstants;
import com.xhh.common.constants.ReapplyConstants;
import com.xhh.interview.service.InterviewService;
import com.xhh.model.interview.pojos.Interview;
import com.xhh.model.reapply.pojos.Preapply;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@RequiredArgsConstructor
public class DelInterviewListener {

    private final InterviewService interviewService;

    @RabbitListener(bindings = @QueueBinding(
        value = @Queue(value = InterviewConstants.QUEUE_NAME_DELETE, durable = "true"),
        exchange = @Exchange(InterviewConstants.EXCHANGE_NAME),
        key = InterviewConstants.DELETE_INTERVIEW_KEY
    ))
    public void listenDelInterview(Long id){
        // 1. 获取复试通知
        Interview interview = interviewService.getById(id);
        // 2.幂等判断，判断复试通知是否存在
        if (interview == null) {
            return;
        }
        // 3.删除
        interviewService.removeById(id);
    }
}
